using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using ScreenTest.Players;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using ScreenTest.Constants;

namespace ScreenTest.Items
{
    class Health : BaseItem
    {
        public int healthAmount;
        Texture2D healthTexture;
        const int HEALTH_SIZE = 32;

        public Health()
        {
            healthAmount = 100;
            isActive = true;
            size = HEALTH_SIZE;
        }

        public override void Load(ContentManager content)
        {
            healthTexture = content.Load<Texture2D>(@"Content\health");
        }

        public override void Draw(GraphicsDevice device, SpriteBatch spriteBatch)
        {
            if (isActive)
                spriteBatch.Draw(healthTexture, new Rectangle((int)position.X - HEALTH_SIZE, (int)position.Y - HEALTH_SIZE, HEALTH_SIZE, HEALTH_SIZE), null, Color.White, 0f, new Vector2(HEALTH_SIZE / 2, HEALTH_SIZE / 2), SpriteEffects.None, 0f);

            //if (isActive)
            //    spriteBatch.Draw(healthTexture, new Rectangle((int)position.X - HEALTH_SIZE, (int)position.Y - HEALTH_SIZE, HEALTH_SIZE, HEALTH_SIZE), null, Color.White);
        }

        public void PickUpHealth(Player player)
        {
            int playerHealth = player.Health;

            playerHealth += healthAmount;
            if (playerHealth > 100)
            {
                playerHealth = 100;
            }

            player.Health = playerHealth;

            isActive = false;
        }

        public override void Touches(Player player)
        {
            if (isActive)
            {
                if (player.GetBoundingBox().Intersects(GetBoundingBox()))
                {
                    PickUpHealth(player);
                }
            }
        }

        public override void Respawn()
        {
            respawnTime = GameConstants.RESPAWN_HEALTH;
            base.Respawn();
        }
    }
}
